﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Protobuf_Gui.Controls
{
    public partial class NewItemBox : Form
    {
        public event Action<string, NewItemBox> NewItem;

        private void OnNewItem(string name, NewItemBox form)
        {
            var handler = NewItem;
            if (handler != null) handler(name, form);
        }

        public NewItemBox()
        {
            InitializeComponent();
            btnDone.Click += BtnDoneClick;
        }

        private void BtnDoneClick(object sender, EventArgs e)
        {
            string value = boxValue.Text;
            if (string.IsNullOrEmpty(value))
            {
                MessageBox.Show("Name must not be empty...", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            OnNewItem(value, this);
        }
    }
}